﻿#include <iostream>
using namespace std;

const int N = 1010;
int main()
{
    int n;
    while (cin >> n) // 多组输⼊ 
    {
        int ret = 1;
        while (ret - 1 <= n) ret *= 2;
        cout << ret / 2 - 1 << endl;
    }
    return 0;
}